package com.sxj.corejava.code15_反射;

import java.lang.reflect.Modifier;
import java.util.Arrays;

/**
 * @author 石小俊
 */
public class Test02_常用方法 {

    public static void main(String[] args) {
        Class c = User.class;
        System.out.println("类全名:" + c.getName());
        System.out.println("类名:" + c.getSimpleName());
        System.out.println("实现的接口列表:" + Arrays.toString(c.getInterfaces()));
        System.out.println("继承的父类:" + c.getSuperclass());
        System.out.println("当前类所在的包名:" + c.getPackage().getName());
        System.out.println("当前类所在的包名:" + c.getPackageName());
        System.out.println("是否是一个接口:" + c.isInterface());

        Class c2 = SomeInterface.class;
        System.out.println("c2是否是一个接口:" + c2.isInterface());

        int modifiers = c.getModifiers();
        System.out.println(modifiers);
        System.out.println("是否是public修饰符:" + Modifier.isPublic(modifiers));
        System.out.println("修饰符:" + Modifier.toString(modifiers));

        // 调用无参构造方法
        try {
            Object obj = c.newInstance();
            System.out.println(obj);
        } catch (InstantiationException e) {
            System.err.println("实例化异常,该类中没有无参构造方法");
        } catch (IllegalAccessException e) {
            System.err.println("非法访问异常,该类的无参构造方法无法被外部访问");
        }

    }

}

interface SomeInterface {

}